/****************************************************************************
 *  QLyrics - A simple lyrics viewer.                                       *
 *  Copyright (C) 2008  hsys <hanshuiys@gmail.com>                          *
 *                                                                          *
 *  This program is free software; you can redistribute it and/or modify    *
 *  it under the terms of the GNU General Public License as published by    *
 *  the Free Software Foundation; either version 3 of the License, or       *
 *  (at your option) any later version.                                     *
 *                                                                          *
 *  This program is distributed in the hope that it will be useful,         *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 *  GNU General Public License for more details.                            *
 *                                                                          *
 *  You should have received a copy of the GNU General Public License       *
 *  along with this program; if not, write to the Free Software Foundation, *
 *  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA       *
 ****************************************************************************/

#ifndef _LYRICSPANEL_H_
#define _LYRICSPANEL_H_

#include <QWidget>
#include <QPainter>
#include <QTime>
#include <QTimer>
#include "basictype.h"
#include "lyricspainter.h"
#include "lyricsdata.h"
#include "lyricsmanager.h"
#include "player.h"

class LyricsPanel : public QWidget {
    Q_OBJECT
public:
    /** Create the panel, and connect necessary signals. */
    LyricsPanel(QWidget* parent = 0);
    /** Delete the panel. */
    virtual ~LyricsPanel();

public slots:
    void setPlayerStatus(Player::Status);
    void setPlayerTime(LyricsTime);
    void setLyricsStatus(LyricsProvider::LyricsStatus);
    void setInterval(int);
    /** Set lyrics data which is going to display. */
    //void setLyrics(LyricsData* lyrics);
    virtual void redraw() {};

protected:
    QTime m_startTime;
    QTimer m_timer;
    LyricsPainter* m_painter;
    bool m_trackPlaying;

    void setScrolling(bool isScrolling);
    void mousePressEvent(QMouseEvent*);
    void mouseMoveEvent(QMouseEvent*);
    void mouseReleaseEvent(QMouseEvent*);
    void resizeEvent(QResizeEvent *);
};

#if 0
/** This class is the base class of all lyrics panel. */
class LyricsNormalPanel : public LyricsPanel {
    Q_OBJECT
public:
    /** Create the panel, and connect necessary signals. */
    LyricsPanel(QWidget* parent = 0);
    /** Delete the panel. */
    virtual ~LyricsPanel();

    /** Set lyrics data which is going to display. */
    void setLyrics(LyricsData* lyrics);

    virtual LyricsTime parseMouseScroll(const QPoint& vec);

protected:
    /** The lyrics data which is going to display. */
    //LyricsData* m_lyrics;
    /** Current time offset of the lyrics. */
    //LyricsTime m_currentOffset;
    QTime m_startTime;
    /** Last status message. */
    QString m_msg;
    QTimer* m_timer;
    LyricsPainter* m_painter;


    /** Called when lyrics file changes. */
    virtual void lyricsChangeEvent(LyricsProvider::LyricsStatus) {};

    /** Set the panel to start/stop scrolling. */
    void setScrolling(bool isScrolling);

    /** Draw a specific text. */
    void drawText(QPainter& painter, int x, int y, const QColor& color, const QString& text);
    /** Draw the message in the middle of the panel. */
    virtual void drawMessage(const QString&);
    /** Draw the frame corresponding to the given time. */
    virtual void drawFrame(LyricsTime) {};
    void updateInterval(int, int);

protected slots:
    void slotStatusChanged(Player::Status);
    void slotTimeChanged(LyricsTime);
    void slotLyricsChanged(LyricsData*, LyricsProvider::LyricsStatus);
    void slotUpdateFrame();
};
#endif
#endif

